package com.buaa.controller;

import com.buaa.model.dto.Relation;
import com.buaa.model.request.PaperRequest;
import com.buaa.model.request.PersonRequest;
import com.buaa.model.solr.Paper;
import com.buaa.service.PaperService;
import com.buaa.service.PersonService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by DELL on 2018/4/12.
 */
@Controller
public class PersonController {

    @Autowired
    PersonService personService;

    @ApiOperation(value="获取人物论文合作关系",httpMethod = "POST", response = Map.class, notes="根据 人名 查询论文合作关系",consumes = "application/json")
    @RequestMapping(value = "/getPaperRelationByName",method = RequestMethod.POST,consumes = "application/json")
    @ResponseBody
    public Object getPaperRelationByName(@RequestBody PersonRequest personRequest){

        String name = personRequest.getName();
        String organization = personRequest.getOrganization();

        if(organization == null || organization.equals("")){
            organization = personService.findPersonListByName(name).get(0).getOrganization();
        }

        Relation relation = personService.getPaperRelationByNameAndOrganization(name,organization);
        return relation;
    }

    @ApiOperation(value="获取人物论文产出曲线图",httpMethod = "POST", response = Map.class, notes="根据 人名 查询论文产出曲线图",consumes = "application/json")
    @RequestMapping(value = "/getPaperChatByName",method = RequestMethod.POST,consumes = "application/json")
    @ResponseBody
    public Object getPaperChatByName(@RequestBody PersonRequest personRequest){

        String name = personRequest.getName();
        String organization = personRequest.getOrganization();

        if(organization == null || organization.equals("")){
            organization = personService.findPersonListByName(name).get(0).getOrganization();
        }

        Map<Integer,Integer> yearAndCount = personService.getPaperChatByNameAndOrganization(name,organization);

        return yearAndCount;
    }
}
